<?php

namespace App\Http\Controllers\API\UI;

use App\Http\Controllers\Controller;
use App\Miya\Tools\TqlTool;
use Illuminate\Http\Request;

class TqlController extends Controller
{
    /**
     * 首页模版
     * @return \Illuminate\Http\JsonResponse
     */
    public function index()
    {
        return $this->buildSelectOptions('tql', 'index');
    }

    /**
     * 移动端首页模版
     * @return \Illuminate\Http\JsonResponse
     */
    public function mindex()
    {
        return $this->buildSelectOptions('tql', 'index', 'wap');
    }

    protected function buildSelectOptions($view, $dir, $type = 'web')
    {
        $data = [];
        collect(TqlTool::buildTqlOptions($view, $dir, $type))
            ->each(function ($value, $key) use (&$data) {
                $data[] = ['id' => $key, 'text' => $value];
            });

        return response()->json($data);
    }
}
